package com.gwcloud.leetcode.offers;

import com.gwcloud.leetcode.common.datastructure.ListNode;

/** 
* @ClassName   : Leetcode0180 
* @author      : ganwei 
* @date        : 2020年6月1日 
* @Description : 删除链表的节点 
*/
public class Leetcode0180 {
	/**
	 * -解题思路
	 */
    public ListNode deleteNode(ListNode head, int val) {
    	if(head == null) {
    		return head;
    	}
    	if(head.val == val) {
    		head = head.next;
    		return head;
    	}
    	ListNode pre = head;
    	ListNode index = head.next;
    	while(index != null) {
    		if(index.val == val) {
    			pre.next = index.next;
    			index = null;
    		}
    	}
    	return head;
    	
    }
}
